package com.wl.mybootwork4.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wl.mybootwork4.entity.Emp;
import com.wl.mybootwork4.services.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wl
 * @version 1.0
 * @date 2022/6/13
 * @description:
 */

@RestController
public class EmpController {

    @Resource
    private EmpService empService;

    @RequestMapping("/getAll")
    public List<Emp> getAll(Model model){
        List<Emp> list=empService.getAll();
        model.addAttribute("empAll",list);
        return list;
    }

    @RequestMapping("/addEmp")
    public String addEmp(Emp emp){
        return String.valueOf(empService.addEmp(emp));
    }


    @RequestMapping("/delEmp/{eno}")
    public String delEmp(@PathVariable("eno") Integer eno){
        System.out.println(eno);
        return String.valueOf(empService.delEmp(eno));
    }

    @RequestMapping("/update")
    public String update(Emp emp){
        return String.valueOf(empService.updateEmp());
    }

}
